package com.miya.demo.support.kafka.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.ProducerListener;
import org.springframework.stereotype.Component;

/**
 * kafka消息发送回调handler
 *
 * @author CaiXiaowei
 * @date 2023/6/1
 */
@Component
@Slf4j
public class KafkaSendResultHandler implements ProducerListener {

    /**
     * @param producerRecord
     * @param recordMetadata
     */
    @Override
    public void onSuccess(ProducerRecord producerRecord, RecordMetadata recordMetadata) {
        log.info("kafka消息发送成功: {}", producerRecord.toString());
    }

    /**
     * @param producerRecord
     * @param recordMetadata
     * @param exception
     */
    @Override
    public void onError(ProducerRecord producerRecord, RecordMetadata recordMetadata, Exception exception) {
        log.info("kafka消息发送失败: {}, error: {}", producerRecord.toString(), exception);
    }
}
